package com.server.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.server.service.IMngUserService;
@Service("MngUserService")
public class MngUserService implements IMngUserService{
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private CommonDataService commonDateService;
	@Autowired
	private UserAssignmentService userAssignmentService;

	@Override
	public Integer deleteAdminUser(String ids) {
		String sql = "delete from %s where id in('%s')";
		return jdbcTemplate.update(String.format(sql, "education.admin_user", ids.replaceAll(",", "','")));
	}
	@Override
	public List<Map<String, Object>> roleList() {
		String sql = "select * from education.admin_role where valid=1";
		List<Map<String, Object>> roleList = jdbcTemplate.queryForList(sql);
		return roleList;
	}
	@Override
	public Boolean check(String nickname) {
		Boolean isSuccess = true;
		String sql = "select * from education.admin_user where nickname='%s'";
		List<Map<String, Object>> list = jdbcTemplate.queryForList(String.format(sql, nickname));
		if(list.size()>0){
			isSuccess = false;
		}
		return isSuccess;
	}
	@Override
	public List<Map<String, Object>> getOrg() {
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		String sql = "select * from education.admin_user where valid=1 and type=3";
		list = jdbcTemplate.queryForList(sql);
		return list;
	}
	@Override
	public List<Map<String, Object>> getField() {
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		String sql = "select * from education.admin_user where valid=1 and type=4";
		list = jdbcTemplate.queryForList(sql);
		return list;
	}
	@Override
	public Integer change(String name, Integer type) {
		String sql = "update %s set useFlag=1 where name in('%s') and type=%d";
		return jdbcTemplate.update(String.format(sql, "education.admin_user", name.replaceAll(",", "','"),type));
	}
	@Override
	public Integer update(String uuids) {
		String sql = "update %s set useFlag=1 where uuid in('%s')";
		return jdbcTemplate.update(String.format(sql, "education.admin_user", uuids.replaceAll(",", "','")));
	}
	@Override
	public Integer deleteD(String ids) {
		String sql = "delete from %s where id in('%s')";
		return jdbcTemplate.update(String.format(sql, "education.dispatch", ids.replaceAll(",", "','")));
	}
}
